import axios from "axios"
import QS from "qs"; //创建文件自带插件，可以直接引用(转型)
import cookin from "js-cookie";
import router from "@/router";
import { ElMessage as $msg } from "element-plus"; 
const state = {
    user:'',
    cunc:{

    }
}
const getters = {
    user(state){
        return state.user 
    },
    // information(state){
    //     return state.information
    // }
}
const mutations = {
    "admins":(state,user) =>{
        state.user = user
    },
    Logout(state){
        let data =QS.stringify({
            _gp: "admin",
            _mt: "info",
        })
        axios.post("http://192.168.1.188:8080/m.api",data,{
            headers:{
              AdminToken:cookin.get("token")
            }
        }).then((res)=>{
            console.log(res);
            let {data,errno,errmsg} = res.data
            if(200==res.data.errno){
                state.user = {} //清空状态
                cookin.remove("token")
                router.push("/Login")
                $msg.success({ message: "退出成功" });
            }
        })
    },
    // getInformation(state,proxy){
    //     state.information = proxy
    // }
}
const actions  = {
    "admins":(context,user) => {
        context.commit('admins',user)
    },
    Logout(context){
        context.commit('Logout')
    },
    // getInformation(context,proxy){
    //     context.commit('getInformation',proxy)
    // }
}



export default{
    state,
    mutations,
    actions,
    getters
}